﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Baimasoft.FrameWork.Base;
using Baimasoft.Manage.SqlServerDAL;

public partial class MobileCode : System.Web.UI.Page
{
    UserManage MyUM = new UserManage();
    LogManage MyLog = new LogManage();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            try
            {
                TxtMobileCode.Focus();
                ALogonID.Text = Request.QueryString["LogonID"].ToString();
            }
            catch
            {
            }
        }
    }

    /// <summary>
    /// 提交
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Submit_ServerClick(object sender, EventArgs e)
    {
        string sLogonID = Request.QueryString["LogonID"].ToString();

        string sMobileCode = TxtMobileCode.Text.ToString().Trim(); //手机验证码
        string sTableCode = MyUM.GetMobileCode(sLogonID);          //数据表中的验证码

        if (sMobileCode == sTableCode && sMobileCode.Length == 6)
        {
            int iClearMobileCode = MyUM.ClearMobileCode(sLogonID); //清空手机验证码
            DataTable UserInfo = new DataTable();

            UserInfo = MyUM.GetLogonUserInfo(sLogonID);
            if (UserInfo.Rows.Count == 0)
            {
                ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('登录失败,请联系管理员!');</script>");
                return;
            }
            Session["Baimasoft_User_LogonID"] = UserInfo.Rows[0][1].ToString().Trim();         //帐户
            Session["Baimasoft_User_Alias"] = UserInfo.Rows[0][2].ToString().Trim();         //别名 
            Session["Baimasoft_Pers_ID"] = UserInfo.Rows[0][3].ToString().Trim();       //人员ID

            Session["Baimasoft_Role_Code"] = UserInfo.Rows[0][4].ToString().Trim();         //功能角色ID
            Session["Baimasoft_DbRole_Code"] = UserInfo.Rows[0][36].ToString().Trim();         //数据角色ID

            Session["Baimasoft_First_Page"] = UserInfo.Rows[0][5].ToString().Trim();         //首页
            Session["Baimasoft_User_BussiID"] = UserInfo.Rows[0][6].ToString().Trim();         //销售网点


            Session["Baimasoft_User_Effective"] = UserInfo.Rows[0][8].ToString().Trim();    //用户帐户是否有效
            Session["Baimasoft_Pers_Code"] = UserInfo.Rows[0][9].ToString().Trim();         //员工号

            Session["Baimasoft_Pers_Name"] = UserInfo.Rows[0][10].ToString().Trim();        //姓名
            Session["Baimasoft_Dept_ID"] = UserInfo.Rows[0][15].ToString().Trim();        //部门ID 
            Session["Baimasoft_Dept_Name"] = UserInfo.Rows[0][21].ToString().Trim();        //部门名称

            Session["Baimasoft_Role_Name"] = UserInfo.Rows[0][31].ToString().Trim();        //功能角色名称
            Session["Baimasoft_DbRole_Name"] = UserInfo.Rows[0][37].ToString().Trim();        //数据角色名称

            try
            {
                string sPerID = (string)Session["Baimasoft_Pers_ID"];
                string sContent = "用户" + (string)Session["Baimasoft_User_LogonID"] + "登录系统成功！";
                string sIP = Page.Request.UserHostAddress;
                MyLog.InsertLog("1", sPerID, sContent, sIP);
            }
            catch
            {
            }
            Response.Redirect("SysManage/index.htm");
        }
        else
        {
            if (sMobileCode == "")
            {
                TxtMobileCode.Focus();
                TxtMobileCode.Text = "";
                ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('请输入手机验证码！');</script>");
                return;
            }
            else
            {
                TxtMobileCode.Focus();
                ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('手机验证码" + TxtMobileCode.Text + "无效，如多次出现验证码无效，请与系统管理人员联系！');</script>");
                TxtMobileCode.Text = "";
                return;
            }
        }
    }
}
